#!/usr/bin/perl
# event_details.cgi
# Display Log Event Details
require './naslog-lib.pl';
&ReadParse();
&header($text{'event_details'},undef,"index",undef,0);

my $log=$in{'log'};
my $filename=$config{$log};
open(FH,"< $filename ")|| &error($text{'log_cannotstat'});
@tmp = <FH>;
@content1 = reverse (@tmp); 
my @content=grep(/info|warning|debug|crit/,@content1);
close(FH);

my $total=@content;
my $line=$in{'line_no'};
my $up_line=($line>1?$line-1:1);
my $down_line=($line<$total?$line+1:$total);
if (! defined $line) {$line=1;}

$disable_up  =( $line==1      ? 'disabled=true' : ' '); 
$disable_down=( $line==$total ? 'disabled=true' : ' '); 

my ($month,$date,$time,$host,$source,$type,$event,@details)=split(' ',$content[$line-1]);
$date=$month . '-' . $date;
$source =~ s/\[\d+\]://;
print <<EOF;
<table width=95%>
<tr>
<td>
<table class=mode1 border=0 width=100% align=center cellspacing=0 cellpadding=0>
    <tr class=mode1>
        <td><b>$text{'table_type'}<b></td>
        <td> $type </td>
    </tr>
    <tr class=mode2>
        <td><b>$text{'table_date'}<b></td>
        <td> $date </td>
    </tr>
    <tr class=mode1>
        <td><b>$text{'table_time'}<b></td>
        <td> $time </td>
    </tr>
    <tr class=mode2>
        <td><b>$text{'table_source'}<b></td>
        <td> $source  </td>
    </tr>
    <tr class=mode1>
        <td><b>$text{'table_event'}<b></td>
        <td> $event  </td>
    </tr>
    <tr class=mode2>
        <td colspan=2 >&nbsp;</td>
    </tr>
    <tr class=mode1>
        <td colspan=2 ><b>$text{'table_details'}<b></td>
    </tr>
</table>
    <br>
    <textarea rows=5 cols=60 readonly id=textdescription 
     name=textdescription> @details  </textarea>
</td>
<td>

<table>
<form method=post onsubmit='return onsubmit_form();'>
<input type=hidden name=log value='$log'>
<input type=hidden name=line_no>
<tr><td>
<input type=submit class=button  name=up value=$text{'up'}  $disable_up
onclick='browse($up_line)'>
</td></tr>
<tr><td>
<input type=submit class=button  name=down value=$text{'down'}  $disable_down
onclick='browse($down_line)'>
</td></tr>
</form>
<tr height=75%><td>&nbsp;</td></tr>
</table></td></tr>
</table>
<script>
function browse(no)
{
	document.forms[0].line_no.value=no;
	document.forms[0].action="event_details.cgi";
}
function onsubmit_form()
{
        document.forms[0].up.disabled = true;
        document.forms[0].down.disabled = true;
}
</script>

EOF

&footer("$log.cgi", $text{$log});

